/*
 * @lc app=leetcode.cn id=404 lang=javascript
 *
 * [404] 左叶子之和
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var sumOfLeftLeaves = function(root) {
    if (root.left === null && root.right === null) {
        return 0
    }
    let result = 0
    function next(root, type) {
        if (root) {
            if (root.left === null && root.right === null && type === 'left') {
                // 如果改的节点是叶子节点 且 标记为 左节点
                result += root.val
            } else {
                next(root.left, 'left')
                next(root.right, 'right')
            }
        }
    }
    next(root, 'left')
    return result
};
// @lc code=end

